<!Doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新书上架...</title>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/main.css"/>
    <script type="text/javascript" src="../js/modernizr.min.js"></script>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        $(function () {
            $("#header").load("../static/header.html");
            $("#left").load("../static/left.html");
            $.get("../user/getLoginInfo.do", {}, function (data) {
                if (data == null) {
                    alert("请先登录。。");
                    location.href = "../user/login.do";
                }
            });
            var lis = "";
            $.get("../book/getType.do", {}, function (data) {
                for (var i = 0; i < data.length; i++) {
                    if(i == 0) {
                        lis += "<option value=\"" + data[i].btype + "\" selected=\"selected\">" + data[i].tName + "</option>"
                    }else {
                        lis += "<option value=\"" + data[i].btype + "\">" + data[i].tName + "</option>"
                    }
                }
                $("#booktype").html(lis);
            });
            $('#submit').click(function () {
                //添加图片信息参数
                // alert("aa");
                var formData = new FormData();
                formData.append('upload', $("#upload")[0].files[0]); //添加图片的信息参数
                //添加其他的信息
                formData.append("bookName", $('#bookName').val());
                formData.append("inventory", $('#inventory').val());
                formData.append("booktype", $('#booktype').val());
                formData.append("price", $('#price').val());
                formData.append("author", $('#author').val());
                formData.append("publishing", $('#publishing').val());
                formData.append("content", $('#content').val());
                formData.append("pubTime", $('#pubTime').val());
                $.ajax({
                    url: "../book/doAddBook.do",
                    type: "post",
                    dataType: "json",
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (data) {
                        alert(data.errorInfo);
                    }
                });
            });
        });
    </script>
</head>
<body>

<div class="container clearfix">
    <div id="header"></div>
    <div id="left"></div>
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="index.html">书籍管理</a><span
                    class="crumb-step">&gt;</span><span class="crumb-name">上架新书</span></div>
        </div>
        <div class="result-wrap">
            <form action="../book/doAddBook.do" method="post" id="myform" enctype="multipart/form-data">
                <div class="config-items">
                    <div class="config-title">
                        <h1><i class="icon-font">&#xe00a;</i>上架新书籍</h1>
                    </div>
                    <div class="result-content">
                        <table width="100%" class="insert-tab">
                            <tbody>
                            <tr>
                                <th width="15%"><i class="require-red">*</i>书名：</th>
                                <td><input type="text" placeholder="请输入书名.." name="bookName" id="bookName"
                                           class="common-text"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>库存数量：</th>
                                <td><input type="number" name="inventory" id="inventory" class="common-text"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>书籍分类：</th>
                                <td>
                                    <select name="booktype" id="booktype">
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>单价：</th>
                                <td><input type="text" id="price" name="price" class="common-text"
                                           placeholder="请输入价格(最多两位小数)..."></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>作者：</th>
                                <td><input type="text" name="author" id="author" class="common-text"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>出版社：</th>
                                <td><input type="text" name="publishing" id="publishing" class="common-text"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>书籍简介：</th>
                                <td>
                                    <textarea rows="5" cols="25" name="content" id="content"
                                              placeholder="请输入书籍简介..."></textarea>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>出版时间：</th>
                                <td><input type="date" name="pubTime" id="pubTime" class="common-text"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>书籍封面：</th>
                                <td><input type="file" id="upload" name="upload" required class="common-text" multiple>
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <!--<input type="submit" value="提交" class="btn btn-primary btn6 mr10">-->
                                    <input type="button" value="提交" class="btn btn-primary btn6 mr10" id="submit">
                                    <input type="button" value="返回" onclick="history.go(-1)" class="btn btn6">
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>